import {getMealData,getMealDetailsData} from "../../api/goods/meal";
export default{
    namespaced:true,
    state:{
        mealData:[],//套餐数据
        title:""//套餐的标题
    },
    mutations:{
        //设置套餐数据
        ["SET_MEAL_DATA"](state,payload){
            state.mealData=payload.mealData;
        },
        //设置套餐标题
        ["SET_TITLE"](state,payload){
            state.title=payload.title;
        }
    },
    actions:{
        //获取套餐数据
        getMeal(conText,payload){
            getMealData(payload).then(res=>{
                if(res.code==200){
                    conText.commit("SET_MEAL_DATA",{mealData:res.data});
                }
            })
        },
        //获取套餐详情
        getMealDetails(conText,payload){
            getMealDetailsData(payload).then(res=>{
                if(res.code==200){
                    conText.commit("SET_TITLE",{title:res.data.title});
                    if(payload.success){
                        payload.success()
                    }
                }
            })
        }
    }
}